package com.isoftstone.common.service.impl;


import com.isoftstone.common.Page;
import com.isoftstone.common.dao.SysDictMapper;
import com.isoftstone.common.entity.SysDict;
import com.isoftstone.common.service.ISysDictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by admin on 16/5/16.
 * 数据字典服务
 */

@Service
public class SysDictService implements ISysDictService {

    @Autowired
    SysDictMapper sysDictMapper;

    @Transactional
    public void saveDict(SysDict sysDict) throws Exception {
        sysDictMapper.saveDict(sysDict);
    }

    @Transactional
    public void updateDict(SysDict sysDict) throws Exception {
        sysDictMapper.updateDict(sysDict);
    }

    public List<SysDict> getSysDictlistPage(Page page) throws Exception {
        return sysDictMapper.getSysDictlistPage(page);
    }

    public List<SysDict> getDictBytype(String type) throws Exception {
        return  sysDictMapper.getDictBytype(type) ;
    }

    public Map<String, String> getDictMap(String type) throws Exception {
        Map<String, String> map = new HashMap<String, String>();
        List<SysDict> list = sysDictMapper.getDictBytype(type);
        for (SysDict dict : list) {
            map.put(dict.getCode(),dict.getCodeName());
        }
        return map;
    }


    public SysDict getDictBytypeAndCode(String type, String code) throws Exception {
        return  sysDictMapper.getDictBytypeAndCode(type,code) ;
    }

    public SysDict getDictById(String dictId) throws Exception {
        return  sysDictMapper.getDictById(dictId);
    }

    @Transactional
    public void deleteDict(String dictId) throws Exception {
        sysDictMapper.deleteDict(dictId) ;
    }

    public List<SysDict> getDictBycodeName( String codeName) throws  Exception{
      return   sysDictMapper.getDictBycodeName(codeName);
    }


    /**
     * 查询工作申请类型
     * @return
     * @throws Exception
     */


    @Override
    public List<SysDict> findJobTypes(String comCode) throws Exception {
        return sysDictMapper.findJobTypes(comCode);
    }

}
